<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/com/include/declare.jspf" %>
<%@ include file="/WEB-INF/jsp/com/include/doctype.jspf" %>
<%-- 
    JSP Name : estimation_login.jsp
    Description : 로그인레이어
    author SJYoon
    since 2012. 7. 22.
    version 1.0
    Modification Information
       since          author              description
    ===========    =============    ===========================
    2012. 7. 22.     SJYoon     최초 생성
--%>
<body style="padding:50px;" cz-shortcut-listen="true">

<script language="javascript">


//로그인 submit
function login() {
    
    var frm = $("#loginMbrForm")[0];

    var loginMsg = document.getElementById("loginMsg");

    var mbrEml = document.getElementById("mbrEml");
    var mbrEml2 = document.getElementById("mbrEml2");
    var pw = document.getElementById("pw") ;
    var saveFlg = document.getElementById("saveFlg") ;


    if (mbrEml.value == "") {
        alert("이메일 앞자리를 입력하십시요");
        mbrEml.focus();
        return ;
    }
    if (mbrEml2.value == "") {
        alert("이메일 뒷자리를 입력하십시요");
        mbrEml2.focus();
        return ;
    }
    if (pw.value == "") {
        alert("비밀번호를  입력하십시요");
        pw.focus();
        return ;
    }    
    
  var mbrEmlA = mbrEml.value+"@"+mbrEml2.value;
  var reqURL = document.getElementById("reqURL").value;
  
       $.post("<c:url value='estimationloginprc.do'/>",
               {
                   'mbrEml' : mbrEmlA,
                   'pw'     : pw.value,
                   'saveFlg' : saveFlg.value
               },
               function(data){
                   var result={};
                   var items = $(data).find("item");
                   items.each(function(index,element){
                      var name = $(this).find("name").text();
                      var value = $(this).find("value").text();
                      result[name] = value;
                   });
                   if(result["result"] =="OK"){

                   //if(reqURL == "") reqURL = '/kr/index.do';

                   //returnReDirectURL(reqURL) ;

                   reloadArea('${cate}' , 'aa', 'bb');
                   
                   if ( "ON" == "${cate}" ){
                       location.reload();
                   }
                   
                   var login_html = "";
                   login_html = "<a href='/kr/mbr/logOut.do'><img src='/kr/images/common/utill_menu_sub08.png' alt='로그아웃' class='first' /></a> ";
                   login_html = login_html + "<a href='/kr/mpg/summeryList.do'><img src='/kr/images/common/utill_menu_sub03.png' alt='마이페이지' /></a> ";
                   login_html = login_html + "<a href='/kr/qa/qa/selectQaPaging.do'><img src='/kr/images/common/utill_menu_sub04.png' alt='Q&amp;A' /></a> ";
                   login_html = login_html + "<a href='http://worldwide.hyundai.com' target='_blank'><img src='/kr/images/common/utill_menu_sub06.png' alt='WORLDWIDE' /></a> ";
                   login_html = login_html + "<a href='/kr/global/globalMenu05.do'><img src='/kr/images/common/utill_menu_sub07.png' alt='소셜허브' /></a> ";
                   
                   $("#utill-menu").html("");
                   $("#utill-menu").html(login_html);
                   
                   return true;
                    
                   }
                   else if (result["result"] == "LCK"){
              
                        mbrEml.value="";
                        pw.value ="";
                       loginMsg.innerHTML="비밀번호 5회 오류로 이 아이디는 사용하실 수 없습니다.";
                       return true;
                       
                   }else if (result["result"] == "NON"){
                       pw.value="";
                       loginMsg.innerHTML="현재 입력하신 아이디가 등록되어 있지 않거나<br />아이디 또는 비밀번호를 잘못 입력하셨습니다.";
                       return true;
                      
                   }else if (result["result"]== "FAIL"){
                       pw.value="";
                       var FailCnt = result["FailCnt"];
                       
                       var inHtml = "아이디 또는 비밀번호 [" + FailCnt + "]회  오류입니다."
                       loginMsg.innerHTML=inHtml ;
                       return true;
                       
                   }
                       
               }  
           );  
       return false;

}


//회원가입(약관동의쪽으로 이동)
function clasAgr(){
    var frm = $("#loginMbrForm")[0];
    frm.action="<c:url value='/mbr/clasAgr.do'/>";
    frm.submit();
}


function returnReDirectURL(reqURL){
    window.location.href = reqURL;
}

//회원가입(기존회원 약관동의쪽으로 이동)
function extLoginForm(){
    var frm = $("#loginMbrForm")[0];

    frm.action="<c:url value='/mbr/extLoginView.do'/>"
    frm.submit();
}




//아이디 찾기
function findNewId(){
    var frm = $("#loginMbrForm")[0];
    frm.action="<c:url value='/mbr/findNewIdView.do'/>";
    frm.submit();
}


//비밀번호찾가
function findNewPw(){
    var frm = $("#loginMbrForm")[0];
    frm.action="<c:url value='/mbr/findNewPwView.do'/>";
    frm.submit();
}

function idSaveTogle(){
    var checkSave = document.getElementById("checkSave");
    var saveFlg = document.getElementById("saveFlg");

    if(checkSave.checked == true ){
        saveFlg.value = "Y";
    }else{
        saveFlg.value = "N";

    }
}

$(document).ready(function() {
    
   var all_cookies = document.cookie.split(';');
   var tmp_cookie ="" ;
   var i, key,val , idx;
   var cookie_name ;
   var cookie_value;
   var mbrEml = document.getElementById("mbrEml");
   var mbrEml2 = document.getElementById("mbrEml2");
   var checkSave = document.getElementById("checkSave");
   var tmpEml = "";
   
   for(i=0 ; i< all_cookies.length ; i++){
       tmp_cookie = all_cookies[i].split('=');
       cookie_name = tmp_cookie[0].replace(/^\s+|\s+$/g,"")    ;
       
       
       if(cookie_name == "saveID"){
       
          if(cookie_name.length > 1){
              cookie_value = unescape(tmp_cookie[1].replace(/^\s+|\s+$/g,""));

              
              tmpEml = cookie_value.replaceAll("\"","") ;
              if(tmpEml != ""){
                  
                  var ml = "${saveMbrEml}";
                  var m_arry = ml.split("@");
                  
                  mbrEml.value = m_arry[0];
                  mbrEml2.value = m_arry[1];
                  var checkSave = document.getElementById("checkSave");
                  checkSave.checked = true ;   
                  var saveFlg = document.getElementById("saveFlg");
                  saveFlg.value = "Y";     
              } 
          }
       }    

   }
});
   
</script>
<!-- 로그인 -->
<div id="loginpopup" class="layerpopup loginpopup" style="top: 250px; display: block; "><div class="layerpopup-inner">
    <div class="layerpopup-head">
        <h1><img src="/kr/images/layerpopup/h1_login.gif" alt="로그인" /></h1>
    </div>
    <form id="loginMbrForm" name="loginMbrForm" method="post"  onsubmit="return false;">
     <input type="hidden" name="saveFlg" id="saveFlg" value="N">   
     <input type="hidden" name="reqURL"  id="reqURL" value="">
    <div class="layerpopup-contents">
        <div class="login-form-wrap">
            <div class="login-form">
                <div>
                    <strong><img src="/kr/images/layerpopup/txt_login01.gif" alt="이메일 아이디" /></strong>
                    <input type="text" name="mbrEml" id="mbrEml" class="txt" style="width:138px;" title="이메일 아이디 입력" />@<input type="text" name="mbrEml2" id="mbrEml2" class="txt" style="width:138px;" title="이메일 아이디 입력" />
                </div>
                <!-- 
                <div>
                    <strong><img src="/kr/images/layerpopup/txt_login03.gif" alt="아이디" /></strong>
                    <input type="text" class="txt" style="width:164px;" title="아이디 입력" />
                </div>
                 -->
                <div class="pw">
                    <strong><img src="/kr/images/layerpopup/txt_login02.gif" alt="비밀번호" /></strong>
                    <input type="password" name="pw" id="pw" class="txt" style="width:300px;" title="비밀번호 입력" />
                </div>
                <input type="image" src="/kr/images/layerpopup/btn_confirm.gif" alt="확인" class="input-btn" onClick="login();" />
            </div>
            <p name="loginMsg" id="loginMsg" class="fail-msg"></p>
            <div class="etc-function">
                <label><input type="checkbox" class="check" id="checkSave" name="checkSave" onClick="idSaveTogle()" /> 아이디 저장</label>
                <span class="bar">|</span>
                <a href="javascript:findNewId();">아이디 찾기</a>, <a href="javascript:findNewPw();">비밀번호 찾기</a>
                <!-- <span class="bar">|</span> -->
                <!-- <a href="javascript:clasAgr();">회원가입</a> -->
            </div>
            <div class="member-conrol">
                <a href="javascript:clasAgr();"><img src="/kr/images/layerpopup/btn_join.gif" alt="회원가입" /></a>
                <a href="javascript:extLoginForm();"><img src="/kr/images/layerpopup/btn_member_replace.gif" alt="기존회원 전환" /></a>
            </div>
            <!-- <p class="repace-comment">* 기존 현대자동차 회원님께서 신 회원제(이메일아이디)로 변환하는 절차 입니다.</p> -->
        </div>
    </div>
    </form>
    <!-- close -->
    <div class="close-area"><div class="close-area-inner">
        <img src="/kr/images/layerpopup/btn_close.gif" alt="닫기" class="close" />
    </div></div>
    <!-- //close -->
</div></div>
<!-- //로그인 -->


</body>
</html>